<?php
/**
 *
 * 쿠키 관리 class
 *
 */

class utilCookie
{
    private $sDomain;

    function utilCookie()
    {
        $this->sDomain = $this->setDomain();
    }

    public function setcookie($sKey, $sVal, $dTime = 0, $onlyPHP = false)
    {
        setcookie($sKey, $sVal, $dTime, '/', $this->sDomain, 0, $onlyPHP);
    }

    private function setDomain()
    {
        $sDomain = $_SERVER['HTTP_HOST'];

        if (strtolower(substr($sDomain, 0, 4)) == 'www.') $sDomain = substr($sDomain, 4);

        if (!is_numeric(substr($sDomain, 0, 2)) && substr($sDomain, 0, 1) != '.') {
            $sDomain = '.'.$sDomain;
        }

        $port = strpos($sDomain, ':');
        if ($port !== false) {
            $sDomain = substr($sDomain, 0, $port);
        }

        return $sDomain;
    }
}
